package border;

import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import square.Direction;
import square.NormalSquare;

public class DoorTest {
	
	@BeforeClass
	public static void setUpBeforeClass() {
	}


	@Before
	public void setUp() {
		square1 = new NormalSquare();
		square2 = new NormalSquare();
		
		
		directionOfBorder = Direction.NORTH;
		isClosedDoor = false;
		
		
		
	}
	
//////////////////////////////////////////////////////////////////////////////////////
	@Test
	public void constructor_twoSquares(){
		 Door door = new Door(square1, square2, directionOfBorder, isClosedDoor);
		 
		 assertFalse(door.isClosed());
		 assertFalse(door.isTerminated());
		 assertFalse(door.isClosed());
		 assertEquals(square1.getBorder(directionOfBorder), door);
		 assertEquals(square2.getBorder(directionOfBorder.getOpposite()), door);
		 
	}
	
	@Test
	public void constructor_oneSquare(){
		Door door = new Door(square1, directionOfBorder, isClosedDoor);
		
		assertFalse(door.isClosed());
		assertFalse(door.isTerminated());
		assertFalse(door.isClosed());
		assertEquals(square1.getBorder(directionOfBorder), door);
		 
	}
	
//////////////////////////////////////////////////////////////////////////////////////
	
	@Test
	public void openDoorTest(){
		boolean isClosed = false;
		Door door = new Door(square1, square2, directionOfBorder, isClosed);
		assertFalse(door.isClosed());
		
	}
	
	@Test
	public void closeDoorTest(){
		boolean isClosed = true;
		Door door = new Door(square1, square2, directionOfBorder, isClosed);
		assertTrue(door.isClosed());
	}
	
/////////////////////////////////////////////////////////////////////////////////////////
	
	@Test
	public void canHaveAsSquareTest_TerminatedDoorCase(){
		Door door = new Door(square1, directionOfBorder, isClosedDoor);
		door.terminate();
		assertTrue(door.canHaveAsSquare(null));
	}
	
	@Test
	public void canHaveAsSquareTest_NotTerminatedSquareAndLegalAmountOfDoorsCase(){
		Door door = new Door(square1, directionOfBorder, isClosedDoor);
		Door door2 = new Door(square2, directionOfBorder, isClosedDoor);
		assertTrue(door.canHaveAsSquare(square2));
	}
	
//////////////////////////////////////////////////////////////////////////////////////////
	
	@Test
	public void isValidDirectionTest_LegalCase(){
		Door door = new Door(square1, directionOfBorder, isClosedDoor);
		assertTrue(door.isValidDirection(directionOfBorder));
	}
	
	@Test
	public void isValidDirectionTest_NoneffectiveDirectionCase(){
		Door door = new Door(square1, directionOfBorder, isClosedDoor);
		assertFalse(door.isValidDirection(null));
	}
	
	@Test
	public void isValidDirectionTest_IllegalDirectionCeilingCase(){
		Door door = new Door(square1, directionOfBorder, isClosedDoor);
		assertFalse(door.isValidDirection(Direction.CEILING));
	}
	
	@Test
	public void isValidDirectionTest_IllegalDirectionFloorCase(){
		Door door = new Door(square1, directionOfBorder, isClosedDoor);
		assertFalse(door.isValidDirection(Direction.FLOOR));
	}
	
	private NormalSquare square1;
	private NormalSquare square2;
	private Direction directionOfBorder;
	private boolean isClosedDoor;
}
